﻿using System;
using System.Collections.Generic;
using System.Text;
using UMLDesigner.Widgets;

namespace UMLDesigner.WorkUnits
{
    public class NewLinkWidgetWorkUnit : IWorkUnit
    {
        public NewLinkWidgetWorkUnit(LinkWidget link)
        {
            this.link = link;
        }

        private LinkWidget link;

        public void Do(Document doc)
        {
            link.SourceSlot = link.SourceWidget.AssignSlot(link.DestinationWidget);
            link.DestinationSlot = link.DestinationWidget.AssignSlot(link.SourceWidget);
            doc.AddWidget(link);
        }

        public void Undo(Document doc)
        {
            link.SourceWidget.DeleteSlot(link.SourceSlot);
            link.DestinationWidget.DeleteSlot(link.DestinationSlot);
            doc.RemoveWidget(link);
        }
    }
}
